const productExceptSelf = (nums) => {
  const output = [];
  const n = nums.length;
  output[0] = 1;
  for (let i = 1; i < n; i++) {
    output[i] = nums[i - 1] * output[i - 1];
  }
  let right = 1;
  for (let i = n - 1; i >= 0; i--) {
    output[i] = right * output[i];
    right *= nums[i];
  }
  return output;
};
